package com.abss.vote.controller;

import com.abss.vote.service.TableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class Table {

    @Autowired
    TableService tableService;

    @RequestMapping("/table")
    public ModelAndView table(){
        List<com.abss.vote.model.Table> ls = tableService.findTable();
        ModelAndView mav = new ModelAndView();
        mav.addObject("table_list",ls);
        mav.setViewName("views/tablename");
        return mav;
    }

    @RequestMapping("/information")
    public ModelAndView information(@RequestParam(name = "tableName",required = false) String tableName){
        ModelAndView mav = new ModelAndView();
        List<com.abss.vote.model.Table> ls = tableService.findInformation(tableName);
        mav.addObject("tableList", ls);
        mav.setViewName("views/table");
        return mav;
    }

}
